import { ref, computed } from 'vue';

export default function useAuth() {
  const token = ref(localStorage.getItem('chunjie__userToken') || '');

  const login = (newToken) => {
    token.value = newToken;
    localStorage.setItem('chunjie__userToken', newToken);
  };

  const logout = () => {
    token.value = '';
    localStorage.removeItem('chunjie__userToken');
  };

  return {
    isLoggedIn: computed(() => !!token.value),
    login,
    logout,
    token
  };
}